﻿namespace BusinessApplication1
{
    using System;
    using System.Windows.Data;


    public class PriorityToTextConverter : IValueConverter
    {
        public enum PriorityValues { High /* Высокий*/, Medium /* Средний*/, Low /* Низкий*/, Unknown };

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
                return getPriorityId((string)value);
                

            else return "Не известно";
        }

        /// <summary>
        /// The inverse of the <see cref="Convert"/>.
        /// </summary>
        /// <param name="value">The value to convert back.</param>
        /// <param name="targetType">The type to convert to (ignored).</param>
        /// <param name="parameter">Optional parameter (ignored).</param>
        /// <param name="culture">The culture of the conversion (ignored).</param>
        /// <returns>The inverse of the input <paramref name="value"/>.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return getPriorityName((PriorityValues)value);
        }

        private string getPriorityName(PriorityValues prio)
        {
            switch (prio)
            {
                case PriorityValues.High: return "Высокий";
                case PriorityValues.Medium: return "Средний";
                case PriorityValues.Low: return "Низкий";
                default: return "Не известно";
            }
        }

        private PriorityValues getPriorityId(string prio)
        {
            switch (prio)
            {
                case "Высокий": return PriorityValues.High;
                case "Средний": return PriorityValues.Medium;
                case "Низкий": return PriorityValues.Low;
                default: return PriorityValues.Unknown;

            }
        }
    }
}
